<template>
  <div class="pass">
    <form>
    <div class="box">
    <h2>更改密码</h2>
    <div class="inputs">
      <div><input name="email" type="email" placeholder="Email" :value="email" @keyup="emailValue"></div>
      <div><input name="password" type="password" placeholder="newPassWord" autocomplete="off" :value="password" @keyup="passwordValue"></div>
      <div><input name="code" type="text" placeholder="code" :value="code" @keyup="codeValue"></div>
    </div>
    <div class="button">
      <span class="code" @click="pushCode">发送验证码</span>
      <button type="button" @click="re">提交</button>
    </div>
  </div>
  </form>
  </div>
</template>

<script>
import { inject, ref } from 'vue';
import {Toast} from "vant"
import {rest,pushCode as pu} from "@/api/login"
import { useRouter } from 'vue-router';
export default {
  name : "Pass",
  setup(){
    const axios = inject("$http")
    const router = useRouter()
    const log = Toast
    let email = ref('');
    function emailValue(e){
      email.value = e.target.value
    }
    let password = ref('')
    function passwordValue(e){
      password.value = e.target.value
    }
    let code = ref('')
    function codeValue(e){
      code.value = e.target.value
    }
    // 发送验证码
    function pushCode (){
      let inputs = [email.value,password.value]
      pu(log,inputs,axios,{email:email.value,flg:true})
    }
    // 提交
    function re(){
      let inputs = [email.value,password.value,code.value]
      rest(inputs,router,axios,log,{email:email.value,password:password.value,code:code.value})
    }
    return {
      email,emailValue,
      password,passwordValue,
      code,codeValue,
      re,pushCode
    }
  }
}
</script>

<style scoped lang="scss">
.pass {
  width: 100vw;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: url("1.jpg") no-repeat 0 0/100%;
  .box {
    width: 50vh;
    height: 50vh;
    border-radius: 15px;
    background: rgba($color: white, $alpha: .7);
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    h2 {
      text-align: center;
      font-size: 24px;
    }
    .inputs {
      width: 100%;
      display: flex;
      flex-direction: column;
      align-items: center;
      div {
        width: 70%;
        padding: 1%;
        input {
          border: 1px solid #aaa;
          border-radius: 15px;
          outline: none;
          width: 100%;
          padding: 4%;
        }
      }
    }
    .button {
      width: 100%;
      height: 70px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: space-between;
      span {
        font-size: 15px;
      }
      button {
        width: 80px;
        height: 30px;
        border-radius: 5px;
        border: none;
        background: rgba($color: #ff0000, $alpha: .7);
      }
    }
  }
}
</style>